--Stargate Gamemode--

AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "password/password.lua" )

include( 'shared.lua' )

//////////////////
/////Gamemode/////
//////////////////

--This happens when the player joins and get spawned--
function GM:PlayerInitialSpawn(ply)

end

--Giving weapons--
function GM:PlayerLoadout(ply)
	
	ply:StripWeapons()
	ply:Give("weapon_physgun")
	ply:Give("weapon_physcannon")
	ply:Give("gmod_tool")
	
	if ply:Team() == 1 then
	
		ply:Give("weapon_dexgun")
		ply:Give("weapon_crowbar")
		ply:Give("weapon_pistol")
		ply:Give("weapon_smg1")
		ply:GiveAmmo(300,"smg1")
		ply:GiveAmmo(5,"smg1_grenate")
		ply:Give("weapon_frag")
		ply:AddFrags(4)
		ply:GiveAmmo(50,"pistol")
		
		ply:SetArmor(100)
		
	elseif ply:Team() == 2 then
	
		ply:Give("weapon_staff")
		ply:Give("weapon_stunstick")
		ply:Give("weapon_zat")
		ply:Give("weapon_hand_device")
		
		ply:SetArmor(100)
	
	elseif ply:Team() == 3 then

		ply:Give("weapon_asura")
		ply:Give("ori_staff_weapon")
		ply:Give("weapon_dexgun")
		
		ply:SetArmor(1000)
	
	end
	
end

--Team tau'ri--
function tauri(ply)
	
	ply:SetTeam(1)
	ply:Spawn()
	if ply:IsPlayer() then
		local message = {
		ply:Name().." has joined the tau'ri."
		}

		local allplayers = player.GetAll( )
		local r = math.random(1,table.Count(message))
 
		for k,v in pairs ( allplayers ) do
			v:PrintMessage( HUD_PRINTTALK, message[ r ] );
		end
	end
end

--Team goa'uld--
function goauld(ply)
	
	ply:SetTeam(2)
	ply:Spawn()
	if ply:IsPlayer() then
		local message = {
		ply:Name().." has joined the goa'uld."
		}
		
		local allplayers = player.GetAll( )
		local r = math.random(1,table.Count(message))
 
		for k,v in pairs ( allplayers ) do
			v:PrintMessage( HUD_PRINTTALK, message[ r ] );
		end
	end
end

--Team alteran--
function alteran(ply)
	
	ply:SetTeam(3)
	ply:Spawn()
	if ply:IsPlayer() then
		local message = {
		ply:Name().." has joined the alteran."
		}
		
		local allplayers = player.GetAll( )
		local r = math.random(1,table.Count(message))
 
		for k,v in pairs ( allplayers ) do
			v:PrintMessage( HUD_PRINTTALK, message[ r ] );
		end
	end
end

--Remember-messages for the timer--
function changeteam1()
	
	local message = {
	"You can change your team by holding 'c' and pressing the button 'Change Team'!"
	}
	
	local allplayers = player.GetAll()
	local r = math.random(1,table.Count(message))

	for k,v in pairs ( allplayers ) do
		v:PrintMessage( HUD_PRINTTALK, message[ r ] );
	end
end

/*function check_message(ply, msg, bool)
 
        if msg == "/menu" then
            RunConsoleCommand("sg_menu", ply:UniqueID())
        end
        
end
 
hook.Add("PlayerSay", "check_message_of_player", check_message)*/

--Timer--
timer.Create("ChangeTeam1", 1200, 0, changeteam1)
timer.Start("ChangeTeam1")

--Adds commands to the console--
concommand.Add("sg_tauri", tauri)
concommand.Add("sg_goauld", goauld)
concommand.Add("sg_alteran", alteran)


